JavaScript

{dialog.object}serverIsAvailable Method

Syntax

{dialog.object}.serverIsAvailable( [timeOut [, successFunction [, errorFunction]]);

Arguments

timeOutnumber

If you don't specify a timeOut, the default value is 300 milliseconds.

successFunctionfunction

The 'successFunction' parameter allows you to pass in an Javascript function to be called once it is determined that the Alpha Anywhere server is available.

errorFunctionfunction

The 'errorFunction' parameter is called if the server is not available.

Description

Tests if the Alpha Anywhere server is available. This is a more comprehensive test than simply testing if an Internet connection is available.

Contrast this method with the UX component's ._getOnlineStatus() method. This method merely tests if there is an internet connection. It does not make an ajax callback to the Alpha Anywhere server. Is merely uses the HTML5 navigator.online property. The .serverIsAvailable() method, on the other hand, does a lightweight callback to the Alpha Anywhere server to test if the server is available.

Discussion

The function will set these variables in the global A5 JavaScript object:

A5._serverAvailable - true/false
A5._serverCheckTime - the time the server availability was last checked.

Example:

Execute the 'refreshList' action is the server is available.

function success() { 
    {dialog.object}.playAction('refreshList');
}

{dialog.object}.serverIsAvailable(300,success);

Example: Passing in an Error Function

var _ok = function() {
    alert('server responded');
};

var _err = function() {
    alert('server did not respond');
}; 

//wait up to 500 milliseconds before calling either the _ok or _err callback function
{dialog.object}.serverIsAvailable(500,_ok,_err);

See Also